function f = M_OnlyFunction(rw_rn,varphi,Xr,Xn,XrXr,XnXn,f_XrXn_U,Xr_f_XrXn_U,Xn_f_XrXn_U );

%% Finding the No-Services equilibrium conditions in Urban regions

    yU_rel                          =  max(rw_rn*XrXr, XnXn);
    IOCC_r_U                        =  zeros(size(XrXr));
    IOCC_n_U                        =  zeros(size(XrXr));
    IOCC_r_U(rw_rn*XrXr >  XnXn)    =  1;
    IOCC_n_U(rw_rn*XrXr <= XnXn)    =  1;
    L_r_U                           =  trapz( Xr,trapz(Xn,  Xr_f_XrXn_U.*IOCC_r_U));
    Emp_r_U                         =  trapz( Xr,trapz(Xn,     f_XrXn_U.*IOCC_r_U));
    L_n_U                           =  trapz( Xr,trapz(Xn,  Xn_f_XrXn_U.*IOCC_n_U));
    Emp_n_U                         =  trapz( Xr,trapz(Xn,     f_XrXn_U.*IOCC_n_U));
    DemandM_wrwn                    =  varphi/(1-varphi)*L_n_U./L_r_U;
    f                               =  ( DemandM_wrwn - rw_rn ).^4;

%% a pata!
% [resid,i_onlyM]     =  min(abs(zeroM_wrwn));
% wrn_M_only          =  rw_rn;
% L_r_M_only          =  L_r_U;
% L_n_M_only          =  L_n_U;
% Q_M_only            =  XM*(L_r_M_only)^varphi*(L_n_M_only)^(1-varphi);
% pSM_M_only          =  (XM/XS)*varphi*(L_n_M_only/L_r_M_only)^(1-varphi); 


   
% %% unpackaging prices   
% p_SR    =  pp;
% wu=XA;
% 
% %% constructing measures of skills distributions in Urban Regions (U= C + F)    
%    
% Xn_f_XrXn_R   =  XnXn.*f_XrXn_R;
% Xr_f_XrXn_R   =  XrXr.*f_XrXn_R;
% 
% % Implied wages and labor market earnings
%     wrR                     =    p_SR*XS;
%     ybar_R                  =    p_SR*cSbar*(1-alphaS)/alphaS+cAbar;       % income threshold for the consumption of Services (presumes zero housing costs in rural areas)
% % Labor Markets
%     yR                      =    max(wu,wrR*XrXr);
%     IOCC_r_R                =    zeros(size(XrXr));  % indicator, occupation choices
%     IOCC_r_R(wu<wrR*XrXr)   =    1;
%     ICS_R                   =    zeros(size(XrXr));  % Indicator, positive 
%     ICS_R(yR>=ybar_R)       =    1;
%     LrR                     =    trapz( Xr,trapz(Xn, Xr_f_XrXn_R .*IOCC_r_R));  % effective labor in routine tasks, rural areas
%     ErR                     =    trapz( Xr,trapz(Xn,    f_XrXn_R .*IOCC_r_R));  % employment in routine tasks, rural areas
%     QA                      =    XA*(pop_R-ErR);
%     QS_R                    =    XS*LrR;
% % Consumption of Services
%     yTop_R                  =    trapz( Xr,trapz(Xn, yR.*f_XrXn_R.*ICS_R));
%     fTop_R                  =    trapz( Xr,trapz(Xn,     f_XrXn_R.*ICS_R));
% % Equilibrium Pricing Condition
%     PP_SR1                  =    alphaS*(yTop_R-cAbar*fTop_R)/(QS_R +(1-alphaS)*cSbar*fTop_R);
% 
% %% Distance (Euclidean)
% 
%  f = (PP_SR1-p_SR)^4;  
%  
%  
